package org.vison.wonfu.framework.configure;

import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.autoconfigure.metrics.web.servlet.WebMvcMetricsAutoConfiguration;
import org.springframework.boot.actuate.metrics.AutoTimer;
import org.springframework.boot.actuate.metrics.web.servlet.DefaultWebMvcTagsProvider;
import org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter;
import org.springframework.boot.actuate.metrics.web.servlet.WebMvcTagsProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.Filter;
import java.util.Arrays;
import java.util.List;

@Configuration
@AutoConfigureAfter(WebMvcMetricsAutoConfiguration.class)
@ConditionalOnClass({DispatcherServlet.class, MeterRegistry.class})
public class WebMetricsFilterConfig {

    // 定义需要排除的接口路径（支持通配符）
    private static final List<String> EXCLUDED_PATHS = Arrays.asList(
            "/health",
            "/actuator/**",
            "/internal/**"
    );

    // 简易的通配符匹配工具（也可使用 Spring 的 AntPathMatcher）
    private boolean matchPath(String requestUri, String pattern) {
        // 实际项目中建议使用 Spring 的 AntPathMatcher，支持更完善的通配符
        return new org.springframework.util.AntPathMatcher().match(pattern, requestUri);
    }

}
